package com.nulldev.util.web.URLUtils.misc;

import java.util.Map;

import com.nulldev.util.JVM.JVM;
import com.nulldev.util.VariableAPI.ArrayUtils;
import com.nulldev.util.web.URLUtils.URLUtils;
import com.nulldev.util.web.legacyURI.LegacyURIUtils;

public class URLQueryParsingTest {

	@SuppressWarnings("deprecation")
	public static void main(String[] args) {
//		final String payload = "?x=1&c=5&a=kfdgdskg0sdk&f=5&d=true&e=[1]";
//		final String payload = "/proxyAPI?uzc=r3---sn-f5f7ln7y.googlevideo.com/videoplayback&uzm=sr-ip&gcr=pl&mn=sn-f5f7ln7y%2Csn-4g5edney&mm=31%2C26&expire=1613797517&ns=zZwA5u99lL6eqAy9yIt0wVAF&c=WEB&mt=1613775637&initcwndbps=591250&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&ms=au%2Conr&n=ow868P9Cy0ZAfYcl&mv=m&mvi=3&gir=yes&ratebypass=yes&itag=18&ip=Z7LNNTGP2LKMZUOVZTIM5TY&id=o-AEJffgnJNGl6jZA2oeSqf_qLEzz6JWewiRZsheeSEblH&vprv=1&txp=5431432&fvip=3&source=youtube&dur=160.055&ei=LUQwYImPMZOYir4PnqWx4AQ&pl=19&lsig=AG3C_xAwRQIgbF5EiXG2XXVrtGAY065jOHYdOjU0Z5ujO-kS9lIh45ECIQDtompuhYn8xrV9PMjKWY-hmWMuNB1rPAFr7X2idTZ38w%3D%3D&mh=6d&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cgcr%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&clen=9067392&mime=video%2Fmp4&sig=AOq0QJ8wRgIhANLIMD0LGc3brH8P51Mn59-kGNW2qZGYtaKnMtsuYcTVAiEA1O8zOv-M4s6tksPHsvGYRMzcjD2pDq9GEPQDEmQGmlw&lmt=1540720790297830&requiressl=yes&uzs=1";
//		final String payload = "/proxyAPI?uzc=manifest.googlevideo.com/api/manifest/hls_variant/expire/1615002552/ei/WKdCYIHHJNOCpASho7gI/ip/188.146.38.200/id/5qap5aO4i9A.0/source/yt_live_broadcast/requiressl/yes/tx/23722139/txs/23722138,23722139/hfr/1/playlist_duration/30/manifest_duration/30/maudio/1/vprv/1/go/1/nvgoi/1/keepalive/yes/fexp/24007246/dover/11/itag/0/playlist_type/DVR/sparams/expire,ei,ip,id,source,requiressl,tx,txs,hfr,playlist_duration,manifest_duration,maudio,vprv,go,itag,playlist_type/sig/AOq0QJ8wRQIhAKeQ4xRii44Usp_TuzPf9G5gFsVMpGTRBM1tGEnYxQa2AiALm4LK7CWW9HnSFJogyqzEHsXT4wgZbiDufpzc6Qq-Lw==/file/index.m3u8&uzm=sr-ip&uzs=1&_opt_dd&ythls";
//		final String payload = "/proxyAPI?uzc=manifest.googlevideo.com/api/manifest/hls_playlist/expire/1615003455/ei/36pCYL2BG5HTyQX_oYagDw/ip/188.146.38.200/id/5qap5aO4i9A.0/itag/91/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/sgoap/gir=yes;itag=139/sgovp/gir=yes;itag=160/hls_chunk_host/r2---sn-f5f7ln7y.googlevideo.com/playlist_duration/30/manifest_duration/30/vprv/1/playlist_type/DVR/initcwndbps/4690/mh/30/mm/44/mn/sn-f5f7ln7y/ms/lva/mv/m/mvi/2/pl/19/dover/11/keepalive/yes/fexp/24007246/beids/9466587/mt/1614981620/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,live,sgoap,sgovp,playlist_duration,manifest_duration,vprv,playlist_type/sig/AOq0QJ8wRAIgAmjW2_Htf9xjPFtjTpRI4K8DUDUsoTPr84k829ypac4CIHt5Hj09QH-9adaxQenCtvAuw1HFa6nS7eJkZN_osNqb/lsparams/hls_chunk_host,initcwndbps,mh,mm,mn,ms,mv,mvi,pl/lsig/AG3C_xAwRQIgY30UHeOYCfg1GPQoDGPrW-87-_dpKsbrtdwKGUoO8IQCIQCQh8vuyym8Ld1YK6801CD_xJNuX7ZoU4Mt4pNpNSDmmg==/playlist/index.m3u8&uzm=sr-ip&uzs=1&_opt_dd&ythls";
		final String payload = "https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/1615004617/ei/aa9CYIPXCo7FyAXq9JzIBQ/ip/188.146.38.200/id/5qap5aO4i9A.0/itag/94/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/sgoap/gir%3Dyes%3Bitag%3D140/sgovp/gir%3Dyes%3Bitag%3D135/hls_chunk_host/r2---sn-f5f7ln7y.googlevideo.com/playlist_duration/30/manifest_duration/30/vprv/1/playlist_type/DVR/initcwndbps/4910/mh/30/mm/44/mn/sn-f5f7ln7y/ms/lva/mv/m/mvi/2/pl/19/dover/11/keepalive/yes/fexp/24007246/beids/23886202/mt/1614982340/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,live,sgoap,sgovp,playlist_duration,manifest_duration,vprv,playlist_type/sig/AOq0QJ8wRQIhAJ-7g_KUs9eYg0Wwp3rOTX4lsH0ixiLObvhC6Y5CwIpcAiAzMUAsx2Faf3920QYqaT2poFXXlvAvkaQbGu7FSCT8dQ%3D%3D/lsparams/hls_chunk_host,initcwndbps,mh,mm,mn,ms,mv,mvi,pl/lsig/AG3C_xAwRQIgLqTbS1N76UwSUjyUNSfLRPHF8QKNga3_AJUXq9VyHCQCIQD_QpHkljZwEFRf5lsG9dZ8Ip01izcq-qcpkIVOHhKmqw%3D%3D/playlist/index.m3u8";
//		ArrayUtils.printLln(URLQueryParser.extract(payload,
//				URLQueryParserOptions.PREFER_EXPERIMENTAL, URLQueryParserOptions.DISABLE_DECODING));
//		{
//			final long s = System.currentTimeMillis();
//			final Map<String, List<String>> u = URLUtils.splitQuery(URLUtils.parseURL_NoAccel(payload));
//			final long e = System.currentTimeMillis();
//			ArrayUtils.printLln(u);
//			JVM.println("=> splitQuery: " + (e - s) + " ms");
//		}
		{
			final long s = System.currentTimeMillis();
			final Map<String, String> u = LegacyURIUtils.queryStringToMap(payload);
			final long e = System.currentTimeMillis();
			ArrayUtils.printLln(u);
			JVM.println("=> queryStringToMap: " + (e - s) + " ms");
		}
		{
			final long s = System.currentTimeMillis();
			final Map<String, String> u = LegacyURIUtils.queryStringToMap_NoDecode(payload);
			final long e = System.currentTimeMillis();
			ArrayUtils.printLln(u);
			JVM.println("=> queryStringToMap-ND: " + (e - s) + " ms");
		}
		try {
			final long s = System.currentTimeMillis();
			final Map<String, String> o = URLUtils.parseQuery(URLUtils.parseURL_NoAccel(payload));
			final long e = System.currentTimeMillis();
			ArrayUtils.printLln(o);
			JVM.println("=> parseQuery: " + (e - s) + " ms");
		} catch (Exception e) {
			JVM.errorln(e);
		}
		try {
			final long s = System.currentTimeMillis();
			final Map<String, String> o = URLUtils.parseQuery(payload);
			final long e = System.currentTimeMillis();
			ArrayUtils.printLln(o);
			JVM.println("=> parseQuery-direct: " + (e - s) + " ms");
		} catch (Exception e) {
			JVM.errorln(e);
		}
	}

}
